#include<bits/stdc++.h>
using namespace std;

struct node
{
	int x, step;
};

int n, k, tt;
int dx[] = {1, -1};
int vis[101000];

void bfs()
{
	queue<node> q;
	q.push({n, 0});
	vis[n] = 1;
	
	while(!q.empty())
	{
		node t = q.front();
		q.pop();
		
		if(t.x == k)
		{
			tt = t.step;
			return ;
		}
		
		for(int i = 0;i < 3;i++)
		{
			int xx;
			if(i == 2)
				xx = t.x*2;
			else
				xx = t.x+dx[i];
			if(xx >= 0 && xx <= 100000 && !vis[xx])
			{
				q.push({xx, t.step+1});
				vis[xx] = 1;
			}
		}
	}
}

int main()
{
	cin>>n>>k;
	bfs();
	cout<<tt;
    return 0;
}

